using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BoosterSpawn : MonoBehaviour
{
	[SerializeField]
	private float[] _radiouses;

	[SerializeField]
	private GameObject _boosterBoj;

	[SerializeField]
	private List<Transform> points;

	private List<Transform> avaliblePoints = new List<Transform>();

	private List<GameObject> _currentBoosters = new List<GameObject>();

	public void Refrash()
	{
		for (int i = 0; i < _currentBoosters.Count; i++)
		{
			Object.Destroy(_currentBoosters[i]);
		}
		_currentBoosters.Clear();
		avaliblePoints.Clear();
		GetComponent<SphereCollider>().radius = _radiouses[NintendoPlayerPrefs.GetInt("Long", 0)];
		StartCoroutine(SwichCollider());
	}

	private void OnTriggerStay(Collider other)
	{
		if (other.tag == "Finish" && !avaliblePoints.Contains(other.transform))
		{
			avaliblePoints.Add(other.transform);
		}
	}

	private IEnumerator SwichCollider()
	{
		yield return new WaitForSeconds(0.4f);
		GetComponent<SphereCollider>().enabled = true;
		yield return new WaitForFixedUpdate();
		yield return new WaitForFixedUpdate();
		GetComponent<SphereCollider>().enabled = false;
		int num = Random.Range(0, NintendoPlayerPrefs.GetInt("Long", 0) + 1);
		if (num > 2)
		{
			num = 2;
		}
		for (int i = 0; i < num; i++)
		{
			GameObject gameObject = Object.Instantiate(_boosterBoj, avaliblePoints[Random.Range(0, avaliblePoints.Count)].position, Quaternion.identity);
			_currentBoosters.Add(gameObject);
			gameObject.transform.position = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, -0.135f);
			gameObject.SetActive(value: true);
		}
	}
}
